//
//  MyButton.m
//  fp
//
//  Created by xingshuai on 2020/11/15.
//

#import "MyButton.h"

@interface MyButton ()

@property (nonatomic,strong) UIImageView *btnImg;
@property (nonatomic,strong) UILabel *btnlabel;

@end

@implementation MyButton

-(UIImageView *)btnImg {
    if (!_btnImg) {
        _btnImg = [[UIImageView alloc]init];
    }
    return _btnImg;
}

-(UILabel *)btnlabel {
    if (!_btnlabel) {
        _btnlabel = [[UILabel alloc]init];
        _btnlabel.text = @"语文";
        _btnlabel.textColor = [UIColor colorWithHexString:@"#606060"];
        _btnlabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
        _btnlabel.textAlignment = NSTextAlignmentCenter;
    }
    return _btnlabel;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.btnImg];
        [self addSubview:self.btnlabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    [self.btnImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(10);
        make.size.mas_offset(CGSizeMake(self.frame.size.width-50, self.frame.size.width-50));
    }];
    
    [self.btnlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.btnImg.mas_bottom).offset(10);
        make.left.right.equalTo(self);
    }];
}

-(void)reloadBtnImg:(NSString *)img btnText:(NSString *)btnText {
    self.btnImg.image = [UIImage imageNamed:img];
    self.btnlabel.text = btnText;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
